<?php

namespace App\Service\User;

use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 用户搜索
 */
class UserSearchService extends BaseService
{
    public function handle()
    {
        // $userId = $this->getUserId();
        $keyword = $this->request->input('keyword', 0);
        $content = intval($keyword);
        //按昵称搜索
        if ($content == 0) {
            $users = UserProfile::searchByNick($keyword);
        } else {
            $users = [UserProfile::getInfoByProfileId($content)];
        }
        $ret = ['list' => []];
        array_walk($users, function ($user) use (&$ret) {
            $ret['list'][] = UserProfile::buildUserItem($user);
        });
        return $ret;
    }
}
